package spring.cloud.tasks.api.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import spring.cloud.tasks.api.domain.TaskDifferentInfo;
import spring.cloud.tasks.api.service.ZooKeeperDatabaseTaskDifferentInfoService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("/rest/v1")
public class ZooKeeperDatabaseTaskDifferentInfoController {

    @Resource
    private ZooKeeperDatabaseTaskDifferentInfoService zooKeeperDatabaseTaskDifferentInfoService;

    //@Audit(type = AuditType.REST)
    @RequestMapping(value = "/different", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public ResponseEntity<Object> different(String zooKeeperClusterKey, HttpServletRequest request)
            throws RuntimeException {
        try {

            List<TaskDifferentInfo> differentInfoList = zooKeeperDatabaseTaskDifferentInfoService.differentByZooKeeperClusterKey(zooKeeperClusterKey);
            return new ResponseEntity<Object>(differentInfoList, HttpStatus.OK);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }

}
